package cn.tedu.flower.manage.content.dao.persist.repository.impl;

import cn.tedu.flower.manage.common.pojo.vo.PageData;
import cn.tedu.flower.manage.common.util.PageInfoToPageDataConverter;
import cn.tedu.flower.manage.content.dao.persist.mapper.OrderMainMapper;
import cn.tedu.flower.manage.content.dao.persist.repository.IOrderMainRepository;
import cn.tedu.flower.manage.content.pojo.entity.OrderMain;
import cn.tedu.flower.manage.content.pojo.vo.OrderMainListItemVO;
import cn.tedu.flower.manage.content.pojo.vo.OrderMainStandardVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;


import java.util.Collection;
import java.util.List;

@Slf4j
@Repository
public class OrderMainRepositoryImpl implements IOrderMainRepository {
    @Autowired
    OrderMainMapper orderMainMapper;
    @Override
    public int insert(OrderMain orderMain) {
        log.debug("开始执行【插入订单】的数据访问，参数：{}", orderMain);

        return orderMainMapper.insert(orderMain);
    }

    @Override
    public int deleteById(Long id) {
        log.debug("开始执行【删除订单】的数据访问，参数：{}", id);

        return orderMainMapper.deleteById(id);
    }

    @Override
    public int deleteByIds(Collection<Long> idList) {
        log.debug("开始执行【批量删除订单】的数据访问，参数：{}", idList);

        return orderMainMapper.deleteByIds(idList);
    }

    @Override
    public int update(OrderMain orderMain) {
        log.debug("开始执行【修改订单】的数据访问，参数：{}", orderMain);

        return orderMainMapper.update(orderMain);
    }

    @Override
    public int count() {
        log.debug("开始执行【统计订单数】的数据访问，无参数");

        return orderMainMapper.selectCount(null);
    }

    @Override
    public OrderMainStandardVO mainStandardById(Long id) {
        log.debug("开始执行【查询订单】的数据访问，参数:{}",id);

        return orderMainMapper.mainStandardById(id);
    }

    @Override
    public PageData<OrderMainListItemVO> list(Integer pageNum, Integer pageSize) {
        log.debug("开始执行【查询订单列表】的数据访问，参数：页码:{},每页数据:{}",pageNum,pageSize );

        PageHelper.startPage(pageNum,pageSize);
        List<OrderMainListItemVO> list = orderMainMapper.list();
        PageInfo<OrderMainListItemVO>pageInfo=new PageInfo<>(list);
        PageData<OrderMainListItemVO> pageData = PageInfoToPageDataConverter.convert(pageInfo);
        return pageData;
    }
}
